package app.util;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletHandler;

public class MinimalServlets {

	public static void main(String[] args) throws Exception {
		Server server = new Server(8083);
		ServletHandler handler = new ServletHandler();
		server.setHandler(handler);
		handler.addServletWithMapping(HelloServlet.class, "/*");
		server.start();
		server.join();
	}
		
	@SuppressWarnings("serial")
	public static class HelloServlet extends HttpServlet{
		@Override
		protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
			response.setContentType("text/html");
			response.setStatus(HttpServletResponse.SC_OK);
			response.getWriter().println("<h1>hello from HelloServlet</h1>");
			//super.doGet(request, response); 	//super.doGet就是返回错误，并打印不支持get方法。
		}	
	}
}
